import os
import numpy as np
import matplotlib.pyplot as plt
import imageio

ART_DIR = os.path.join(os.path.dirname(__file__), "..", "artifacts")
os.makedirs(ART_DIR, exist_ok=True)

# Generate a dummy training curve
x = np.arange(0, 100)
y = np.tanh((x - 20) / 20.0) + 0.1 * np.random.randn(len(x))
plt.figure(figsize=(8, 4))
plt.plot(y, label="Episode reward (placeholder)")
plt.xlabel("Episode")
plt.ylabel("Reward")
plt.title("Training Reward Curve (Placeholder)")
plt.grid(True, alpha=0.3)
plt.legend()
plt.tight_layout()
plt.savefig(os.path.join(ART_DIR, "training_curve.png"))
plt.close()

# Generate a simple moving square GIF
frames = []
size = 10
cell = 16
H = size * cell
W = size * cell
for t in range(60):
    img = np.ones((H, W, 3), dtype=np.uint8) * 255
    # obstacle wall
    img[:, W//2-8:W//2+8] = 0
    # goal
    img[H-32:H-16, W-32:W-16] = np.array([50, 205, 50], dtype=np.uint8)
    # agent moving
    ax = min(H-16, t * 4)
    ay = min(W-16, t * 4)
    img[ax:ax+16, ay:ay+16] = np.array([30, 144, 255], dtype=np.uint8)
    frames.append(img)

imageio.mimsave(os.path.join(ART_DIR, "demo.gif"), frames, format="GIF", fps=10)
print(f"[INFO] Placeholder artifacts written to {ART_DIR}")